<?php

// +----------------------------------------------------------------------
// | 文件 UserDailyTopEvent.class.php
// +----------------------------------------------------------------------
// | 说明 用户每日之星的权重
// +----------------------------------------------------------------------
// | 
// +----------------------------------------------------------------------
// | Author: 谢赤心 Legend. <xcx_legender@qq.com>
// +----------------------------------------------------------------------

namespace Api\Event\Cache;
use Api\Event\CacheEvent;

class UserDailyTopEvent implements ICacheEvent
{   

    const DB = 2;

    static public function set($date, $uid, $score)
    {
        $redis = CacheEvent::instance(self::DB);
        $key   = "IMBA.STATIS.USER.DAILYTOP.{$date}";

        if (!$redis->exists($key)){
            $init = true;
        }

        $redis->zIncrBy($key, $score, (int)$uid);
        if ($init){
            $redis->expire($key, 2*7*24*3600); // 设置两周过期
        }
    }

    static public function get($date, $top = 10)
    {
        $redis = CacheEvent::instance(self::DB);
        $key   = "IMBA.STATIS.USER.DAILYTOP.{$date}";
        return $redis->zRevRange($key, 0, 10);
    }

}